<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>打飞机</title>
    <link rel="stylesheet" href="css/reset.css">
    <style>
        p {
            position: absolute;
            top: 5px;
            left: 10px;
            color: black;
            font-weight: bolder;
            font-size: 16px;
            display: none;
        }
        div {
            position: absolute;
            top:200px;
            left: 50px;
            width: 200px;
            height: 200px;
            background-color: rgba(0,255,255,0.5);
            text-align: center;
            border: 2px solid gray;
            border-radius: 10px;
            display: none;
        }
        span {
            position: absolute;
            top: 30px;
            left: 40px;
            width: 120px;
            height: 80px;
            text-align:left;
            display: inline-block;
            border: 1px solid gray;
            font-size: 20px;
            line-height: 40px;
            border-radius: 10px;
        }
        button {
            position: absolute;
            outline: none;
            top: 130px;
            left: 40px;
            width: 120px;
            height: 40px;
            border: none;
            color: white;
            background-color: tomato;
            border-radius: 10px;
            font-size: 24px;
            line-height: 40px;
            font-weight: bolder;
        }
    </style>
</head>
<body>
    <canvas id="canvas"></canvas>
    <p>得分：0分</p>
    <img src="img/lod.gif" style="position: absolute" alt="">
    <div>
<!--       太菜了！！！好好练练吧-->
<!--       还可以！！！下次继续努力-->
<!--       厉害了！！！做的不错-->
<!--       真的拽！！！干的漂亮-->
<!--       无人可挡！！你----无敌了-->
        <span></span>
        <button>再来一次</button>
    </div>
</body>
<script src="js/preload.js">//预加载</script>
<script src="js/isPC.js">//设备检测</script>
<script src="js/bgScroll.js">//背景滚动</script>
<script src="js/rect.js">//矩形构造</script>
<script>
    var canvas=document.getElementById('canvas');
    var ctx=canvas.getContext('2d');
    var loadingImg=document.querySelector('img');
    var p=document.querySelector('p');
    var div=document.querySelector('div');
    var span=document.querySelector("div span");
    var but=document.querySelector('div button');
    div.style.display='none';
    //计分
    var score=0;
    //判断设备
    if(isPC()){
        //PC
        canvas.width=320;
        canvas.height=568;
    } else {
        //移动
        canvas.width=window.innerWidth;
        canvas.height=window.innerHeight;
    }
    loadingImg.style.width=300+'px';
    loadingImg.style.height=186+'px';
    loadingImg.style.left=canvas.width/2-150+"px";
    loadingImg.style.top=canvas.height/2+62+"px";
    div.style.left=canvas.width/2-100+"px";
    div.style.top=canvas.height/2-100+"px";
    //预加载
    window.onload=function(){
        loading(gameStart);
    }
    //游戏开始
    var timer=null;
    function gameStart(){
        //隐藏loadingImg
        loadingImg.style.display='none';
        p.style.display='block';
        timer=setInterval(begin,30)
    }
    function begin(){
        ctx.clearRect(0,0,canvas.width,canvas.height)
//        1.背景滚动
        bgRoll();
//        2.英雄
        hero.draw();
//        3.键盘控制
        control();
//        4.创建敌机
        createEnemy();
//        5.创建子弹
        createButtle();
//        6.创建奖励
        createProp();
//        7.碰撞检测/敌机、子弹、奖励的运动
        allMove();
    }
</script>
<!--hero.js中，全局变量hero用到了canvas的宽高，所以必须写到后边-->
<script src="js/hero.js">//英雄</script>
<script src="js/control.js">//键盘控制，触屏控制飞机</script>
<script src="js/rand.js">//随机数</script>
<script src="js/Enemy.js">//敌机</script>
<script src="js/check.js">//碰撞+运动</script>
<script src="js/Bullet.js">//子弹</script>
<script src="js/Prop.js">//奖励</script>
</html>










